home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / jpi / gameinte.bas < prev    next >
BASIC Source File  |  1998-01-29  |  23KB  |  599 lines

  1. Attribute VB_Name = "GameInterface"
  2. Global Const EXTRABORDER = 5
  3. Global Const MouseDragThreshhold = 4
  4.  
  5. Global Const MAXMOUSEBUTTONS = 5
  6. 'Mouse
  7. Type MousePoint
  8.   DragStartPosition As Point3D
  9.   DragCurrentPosition As Point3D
  10.   IsDragging As Boolean
  11.   Position As Point3D
  12.   OldButtonStates(1 To MAXMOUSEBUTTONS) As Boolean
  13.   ButtonStates(1 To MAXMOUSEBUTTONS) As Boolean
  14.   CursorPic As Integer
  15. End Type
  16. Public Mouse As MousePoint
  17.  
  18. 'Keyboard
  19. Global Const KEY_SHIFT = 16
  20. Global Const KEY_ENTER = 13
  21. Global Const KEY_ESCAPE = 27
  22. Global Const KEY_T = 84
  23. Global Const KEY_S = 83
  24. Global Const KEY_D = 68
  25. Global Const KEY_CONTROL = 17
  26. Global Const KEY_ALT = 18
  27. Global Const KEY_TAB = 9
  28.  
  29. Global Const KEY_UP = 38
  30. Global Const KEY_DOWN = 40
  31. Global Const KEY_LEFT = 37
  32. Global Const KEY_RIGHT = 39
  33.  
  34.  
  35. Global KeyStates(250) As Boolean
  36.  
  37. Type ObjectSelect
  38.   MaxSelected As Integer
  39.   SelectedList(MAXOBJECTS) As Integer
  40. End Type
  41. Type Interflags
  42.   WritingAMessage As Boolean
  43.   Message As String
  44.   PlacingABuilding As Boolean
  45.   PlaceIndex As Integer
  46. End Type
  47. Global InterfaceFlags As Interflags
  48. Global ObjectSelectedList As IndexGroup
  49. 'Real stuff
  50. Public Const INTERFACEWIDTH = 320
  51. Public Const INTERFACEHEIGHT = 200
  52. Public Const HALFINTERFACEWIDTH = INTERFACEWIDTH / 2
  53. Public Const HALFINTERFACEHEIGHT = INTERFACEHEIGHT / 2
  54. Private Const NOCONTROL = 0
  55.  
  56.  
  57. Private Const MAXPROPERTIES = 10
  58. Public Const CONTROLPROPERTY_TEXT = 1
  59. Public Const CONTROLPROPERTY_PICTURE = 2
  60. Public Const CONTROLPROPERTY_STATE = 3
  61.  
  62. Type PropertyArray
  63.   Properties(MAXPROPERTIES) As Variant
  64. End Type
  65. Type ControlObject
  66.   Outline As RECT
  67.   ControlProperties As PropertyArray
  68.   ControlType As Integer
  69. End Type
  70. Private Const MAXCONTROLAMOUNT = 30
  71. Type ControlGroup
  72.   ControlAmount As Integer
  73.   ControlObjects(MAXCONTROLAMOUNT) As ControlObject
  74. End Type
  75. Type InterfaceReturnObj
  76.   Controls As ControlGroup
  77.   Canceled As Boolean
  78. End Type
  79. Type InterfaceObj
  80.   BackgroundPic As Integer
  81.   BackgroundSound As String
  82.   MouseCursorPic As Integer
  83.   Controls As ControlGroup
  84.   ControlFocus As Integer
  85. End Type
  86. Public Const CONTROLTYPE_PICTUREBOX = 1
  87. Public Const CONTROLTYPE_BUTTONLARGE = 2
  88. Public Const CONTROLTYPE_LABEL = 3
  89. Public Const CONTROLTYPE_TEXTBOX = 4
  90. Public Function CreateControl(ControlType, X, Y, Width, Height, Content) As ControlObject
  91. Dim NewControl As ControlObject
  92. NewControl.ControlType = ControlType
  93. Select Case ControlType
  94. Case CONTROLTYPE_PICTUREBOX
  95.   NewControl.ControlProperties.Properties(CONTROLPROPERTY_PICTURE) = Content
  96.   NewControl.Outline.Top = Y - Int(Height / 2)
  97.   NewControl.Outline.bottom = Y + Int(Height / 2)
  98.   NewControl.Outline.Left = X - Int(Width / 2)
  99.   NewControl.Outline.Right = X + Int(Width / 2)
  100. Case CONTROLTYPE_BUTTONLARGE
  101.   NewControl.ControlProperties.Properties(CONTROLPROPERTY_TEXT) = Content
  102.   NewControl.ControlProperties.Properties(CONTROLPROPERTY_STATE) = False
  103.   NewControl.Outline.Top = Y
  104.   NewControl.Outline.bottom = Y + Height
  105.   NewControl.Outline.Left = X
  106.   NewControl.Outline.Right = X + Width
  107. Case CONTROLTYPE_LABEL
  108.   NewControl.ControlProperties.Properties(CONTROLPROPERTY_TEXT) = Content
  109.   NewControl.Outline.Top = Y
  110.   NewControl.Outline.bottom = Y + Height
  111.   NewControl.Outline.Left = X
  112.   NewControl.Outline.Right = X + Width
  113. Case CONTROLTYPE_TEXTBOX
  114.   NewControl.ControlProperties.Properties(CONTROLPROPERTY_TEXT) = Content
  115.   NewControl.Outline.Top = Y - Int((Height * FONT_SPACINGY) / 2)
  116.   NewControl.Outline.bottom = Y + Int((Height * FONT_SPACINGY) / 2)
  117.   NewControl.Outline.Left = X - Int((Width * FONT_SPACINGX) / 2)
  118.   NewControl.Outline.Right = X + Int((Width * FONT_SPACINGX) / 2)
  119. End Select
  120. CreateControl = NewControl
  121. End Function
  122. Public Function ProjectRectToCenterScreen(RectToConvert As RECT) As RECT
  123. ProjectRectToCenterScreen.Left = (RectToConvert.Left - HALFINTERFACEWIDTH) + ResolutionMidX
  124. ProjectRectToCenterScreen.Right = (RectToConvert.Right - HALFINTERFACEWIDTH) + ResolutionMidX
  125. ProjectRectToCenterScreen.Top = (RectToConvert.Top - HALFINTERFACEHEIGHT) + ResolutionMidY
  126. ProjectRectToCenterScreen.bottom = (RectToConvert.bottom - HALFINTERFACEHEIGHT) + ResolutionMidY
  127. End Function
  128. Private Sub DrawInterface(Interface As InterfaceObj)
  129. Call GraphicsEngine.SplashGraphic(InGameConstants(InGameConstant_PICINDEX_ProgramBackground))
  130. Call GraphicsEngine.DisplayText("JPI v" & VERSION, ResolutionMidX - HALFINTERFACEWIDTH, ResolutionMidY - HALFINTERFACEHEIGHT, PALLETE_YELLOW)
  131. For I = 1 To Interface.Controls.ControlAmount
  132.   'Display controls
  133.   With Interface.Controls.ControlObjects(I)
  134.     Select Case .ControlType
  135.     Case CONTROLTYPE_PICTUREBOX
  136.       Call GraphicsEngine.PutGraphicOntoBackBuffer(.Outline.Left + Pics(.ControlProperties.Properties(CONTROLPROPERTY_PICTURE)).HalfWidth, .Outline.Top + Pics(.ControlProperties.Properties(CONTROLPROPERTY_PICTURE)).HalfHeight, .ControlProperties.Properties(CONTROLPROPERTY_PICTURE), BltType_Mask)
  137.     Case CONTROLTYPE_BUTTONLARGE
  138.       Call GraphicsEngine.PutGraphicOntoBackBuffer(.Outline.Left + Pics(InGameConstants(InGameConstant_PICINDEX_ButtonLarge)).HalfWidth, .Outline.Top + Pics(InGameConstants(InGameConstant_PICINDEX_ButtonLarge)).HalfHeight, InGameConstants(InGameConstant_PICINDEX_ButtonLarge), BltType_Fast)
  139.       Call GraphicsEngine.DisplayTextCenterRelative(.ControlProperties.Properties(CONTROLPROPERTY_TEXT), .Outline.Left + 70, .Outline.Top + 6, PALLETE_WHITE)
  140.     Case CONTROLTYPE_TEXTBOX
  141.       Call GraphicsEngine.DisplayText(.ControlProperties.Properties(CONTROLPROPERTY_TEXT), .Outline.Left, .Outline.Top + 1, PALLETE_YELLOW)
  142.       Call GraphicsEngine.GethDC
  143.       Call GraphicsEngine.DrawBox(.Outline.Left, .Outline.Top + 2, .Outline.Right, .Outline.bottom - 1, 255, 255, 255, 0, 0, 0, LINEMODE_NORMAL)
  144.       Call GraphicsEngine.ReleasehDC
  145.     Case CONTROLTYPE_LABEL
  146.       Call GraphicsEngine.DisplayTextCenterRelative(.ControlProperties.Properties(CONTROLPROPERTY_TEXT), .Outline.Left + ((.Outline.Right - .Outline.Left) / 2), .Outline.Top + ((.Outline.bottom - .Outline.Top) / 2), PALLETE_YELLOW)
  147.     End Select
  148.   End With
  149. Next I
  150. End Sub
  151. Public Function RunStaticInterface(InterfaceToRun As InterfaceObj) As InterfaceReturnObj
  152. Dim InterfaceReturn As InterfaceReturnObj, Interface As InterfaceObj
  153. ViewForm.KeyboardInputBox.Text = ""
  154. Interface = InitializeInterfaceObj(InterfaceToRun)
  155. Call ClearKeyStates
  156. If InterfaceToRun.BackgroundSound <> "" Then Call Sound.Play_LoopSound(Sound.GetSoundIndex(InterfaceToRun.BackgroundSound), 100)
  157. Do
  158.   
  159.   DoEvents
  160.   If Interface.ControlFocus <> NOCONTROL Then
  161.     If RunControlKeyboardInput(Interface.Controls.ControlObjects(Interface.ControlFocus)) = True Then
  162.       Interface.ControlFocus = NOCONTROL
  163.     End If
  164.   End If
  165.   For I = 1 To Interface.Controls.ControlAmount
  166.     If RunControlMouseInput(Interface.Controls.ControlObjects(I)) = True Then
  167.       Select Case Interface.Controls.ControlObjects(I).ControlType
  168.       Case CONTROLTYPE_TEXTBOX
  169.         Interface.ControlFocus = I
  170.         ViewForm.KeyboardInputBox.Text = Interface.Controls.ControlObjects(I).ControlProperties.Properties(CONTROLPROPERTY_TEXT)
  171.         ViewForm.KeyboardInputBox.SelStart = Len(ViewForm.KeyboardInputBox.Text)
  172.         ViewForm.KeyboardInputBox.MaxLength = (Interface.Controls.ControlObjects(I).Outline.Right - Interface.Controls.ControlObjects(I).Outline.Left) / FONT_SPACINGX
  173.       End Select
  174.       If Interface.Controls.ControlObjects(I).ControlType = CONTROLTYPE_BUTTONLARGE Then
  175.         Exit Do
  176.       End If
  177.     End If
  178.   Next I
  179.   Call GraphicsEngine.ClearBackBuffer
  180.   Call DrawInterface(Interface)
  181.   GraphicsEngine.SwapScreen
  182.   'Display mouse cursor (make a sub DisplayMousecursor(CursorPic)
  183.   If KeyStates(KEY_ESCAPE) = True Then
  184.     RunStaticInterface.Canceled = True
  185.     Exit Do
  186.   End If
  187. Loop
  188. Call Sound.Stop_Sounds
  189. RunStaticInterface.Controls = Interface.Controls
  190. ViewForm.KeyboardInputBox.MaxLength = 0
  191. End Function
  192. Public Sub RunImmediateInterface(Interface As InterfaceObj)
  193. For I = 1 To Interface.Controls.ControlAmount
  194. '  Call RunControl(Interface.Controls.ControlObjects(I))
  195. Nex